# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=rssguard
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.7.4
pkgrel=1
pkgdesc='Feed reader and podcast player which supports RSS/ATOM/JSON (mingw-w64)'
arch=(any)
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/martinrotter/rssguard'
msys2_references=(
  'archlinux: rssguard'
)
license=('spdx:GPL-3.0-only')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-mpv"
         "${MINGW_PACKAGE_PREFIX}-nodejs"
         "${MINGW_PACKAGE_PREFIX}-qt6-5compat"
         "${MINGW_PACKAGE_PREFIX}-qt6-base"
         "${MINGW_PACKAGE_PREFIX}-qt6-declarative"
         "${MINGW_PACKAGE_PREFIX}-qt6-multimedia"
         #"${MINGW_PACKAGE_PREFIX}-qt6-webengine"
         "${MINGW_PACKAGE_PREFIX}-sqlite")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-qt6-tools")
source=("https://github.com/martinrotter/${_realname}/archive/${pkgver}/${_realname}-${pkgver}.tar.gz"
        001-cmake-update.patch
        002-comply-to-fhs.patch
        003-fix-default-setting.patch
        004-misc-fixes.patch)
sha256sums=('2230f80a800171f8ef9f4085046b9a277eed0b059f13f194408a88df900306d4'
            'a3a37152bb4dada9f241b2057c07758faf4d809be6ff22118e8161507bf007af'
            'a57a05c0e21fc587c478b20f393434e0a31495b51c31367729d14dea03f2773e'
            'e4828f6f9efecce3a5055df5dbb93fb3f07e4e89d17049b6cd64b94c64c6384f'
            'f3a7cbe333ace5caff7bbad5a2868e0b5e74939e1738740c54d1b0271a42ff07')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Np1 -i "${srcdir}/${_patch}"
  done
}

prepare() {
  cd ${_realname}-${pkgver}

  apply_patch_with_msg \
    001-cmake-update.patch \
    002-comply-to-fhs.patch \
    003-fix-default-setting.patch \
    004-misc-fixes.patch
}

build() {
  CXXFLAGS+=" -Wno-deprecated-declarations -Wno-ignored-attributes"
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  cmake \
    -GNinja \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_WITH_QT6=ON \
    -DREVISION_FROM_GIT=OFF \
    -DNO_UPDATE_CHECK=ON \
    -DNO_LITE=OFF \
    -S ${_realname}-${pkgver} \
    -B build-${MSYSTEM}

  cmake --build build-${MSYSTEM}
}

package() {
  DESTDIR="${pkgdir}" cmake --install build-${MSYSTEM}

  install -Dm644 ${_realname}-${pkgver}/LICENSE.md \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.md
}

